﻿using System;
using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Docking;
using QuanLyKho.Server.BLL;
using DevExpress.Xpf.Grid;
using QuanLyKho.Server;
using QuanLyKho.CommonControl;


namespace QuanLyKho
{
    /// <summary>
    /// Interaction logic for frmThongKeTongBNChayThan.xaml
    /// </summary>
    public partial class ucDSXuatKho : UserControl
    {
        public ucDSXuatKho()
        {
            InitializeComponent();
        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            DockLayoutManager dockLayoutManager = this.Parent as DockLayoutManager;
            BaseLayoutItem bli = dockLayoutManager.ActiveMDIItem;
            if (bli != null)
            {
                dockLayoutManager.DockController.Close(bli);
            }
        }

        private void btnTimKiem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PhieuXuatThuocBLL bll = new PhieuXuatThuocBLL();
                gridPhieuXuat.ItemsSource = bll.RetrievePhieuXuatByDate(calendar.StartDate, calendar.EndDate);
                gridPhieuXuat.RefreshData();
            }
            catch (Exception)
            {
                DXMessageBox.Show("Tìm kiếm không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void BarButtonItemXemChiTiet_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            PhieuXuatThuoc phieuXuat = tbvPhieu.FocusedRow as PhieuXuatThuoc;
            if(phieuXuat == null)
                return;
            
            // Khởi tạo UserControl
            ucXuatKho xuatKho = new ucXuatKho();
            xuatKho.phieuXuatCurrent = phieuXuat;

            // Hiển thị dialog màn hình phiếu xuất kho
            DXWindow window = new DXWindow();
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.ResizeMode = ResizeMode.CanResize;
            window.Width = window.Width + 10;
            window.Height = window.Height + 10;
            window.Title = "Xuất kho";
            ThemeManager.SetThemeName(window, "Office2007Blue");
            window.Content = xuatKho;
            window.ShowDialog();
        }

        private void btnThemMoi_Click(object sender, RoutedEventArgs e)
        {
            // Hiển thị dialog màn hình thêm mới phiếu xuất kho
            DXWindow window = new DXWindow();
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.ResizeMode = ResizeMode.CanResize;
            window.Width = window.Width + 10;
            window.Height = window.Height + 10;
            window.Title = "Xuất kho";
            ThemeManager.SetThemeName(window, "Office2007Blue");
            window.Content = new ucXuatKho();
            window.ShowDialog();
        }

        private void BarButtonItemXemDanhSachTruocKhiIn_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            tbvPhieu.ShowPrintPreviewDialog(QuanLyKhoGlobal.MainWindow);
        }
    }
}
